home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
bbsutil
/
bsrc_250.zip
/
ZSEND.C
< prev
Wrap
Text File
|
1991-09-15
|
35KB
|
997 lines
/*--------------------------------------------------------------------------*/
/* */
/* */
/* ------------ Bit-Bucket Software, Co. */
/* \ 10001101 / Writers and Distributors of */
/* \ 011110 / Freely Available<tm> Software. */
/* \ 1011 / */
/* ------ */
/* */
/* (C) Copyright 1987-91, Bit Bucket Software Co., a Delaware Corporation. */
/* */
/* */
/* Zmodem file transmission module */
/* */
/* */
/* For complete details of the licensing restrictions, please refer */
/* to the License agreement, which is published in its entirety in */
/* the MAKEFILE and BT.C, and also contained in the file LICENSE.250. */
/* */
/* USE OF THIS FILE IS SUBJECT TO THE RESTRICTIONS CONTAINED IN THE */
/* BINKLEYTERM LICENSING AGREEMENT. IF YOU DO NOT FIND THE TEXT OF */
/* THIS AGREEMENT IN ANY OF THE AFOREMENTIONED FILES, OR IF YOU DO */
/* NOT HAVE THESE FILES, YOU SHOULD IMMEDIATELY CONTACT BIT BUCKET */
/* SOFTWARE CO. AT ONE OF THE ADDRESSES LISTED BELOW. IN NO EVENT */
/* SHOULD YOU PROCEED TO USE THIS FILE WITHOUT HAVING ACCEPTED THE */
/* TERMS OF THE BINKLEYTERM LICENSING AGREEMENT, OR SUCH OTHER */
/* AGREEMENT AS YOU ARE ABLE TO REACH WITH BIT BUCKET SOFTWARE, CO. */
/* */
/* */
/* You can contact Bit Bucket Software Co. at any one of the following */
/* addresses: */
/* */
/* Bit Bucket Software Co. FidoNet 1:104/501, 1:343/491 */
/* P.O. Box 460398 AlterNet 7:491/0 */
/* Aurora, CO 80046 BBS-Net 86:2030/1 */
/* Internet f491.n343.z1.fidonet.org */
/* */
/* Please feel free to contact us at any time to share your comments about */
/* our software and/or licensing policies. */
/* */
/* */
/* This module is based largely on a similar module in OPUS-CBCS V1.03b. */
/* The original work is (C) Copyright 1986, Wynn Wagner III. The original */
/* authors have graciously allowed us to use their code in this work. */
/* */
/*--------------------------------------------------------------------------*/
/* Include this file before any other includes or defines! */
#include "includes.h"
/*--------------------------------------------------------------------------*/
/* Private routines */
/*--------------------------------------------------------------------------*/
void ZS_SendBinaryHeader (unsigned short, byte *);
void ZS_32SendBinaryHeader (unsigned short, byte *);
void ZS_SendData (byte *, int, unsigned short);
void ZS_32SendData (byte *, int, unsigned short);
void ZS_SendByte (byte);
int ZS_GetReceiverInfo (void);
int ZS_SendFile (int, int);
int ZS_SendFileData (int);
int ZS_SyncWithReceiver (int);
void ZS_EndSend (void);
/*--------------------------------------------------------------------------*/
/* Private data */
/*--------------------------------------------------------------------------*/
static FILE *Infile; /* Handle of file being sent */
static long Strtpos; /* Starting byte position of */
/* download */
static long LastZRpos; /* Last error location */
static long ZRPosCount; /* ZRPOS repeat count */
static long Txpos; /* Transmitted file position */
static int Rxbuflen; /* Receiver's max buffer */
/* length */
static int Rxflags; /* Receiver's flags */
/*--------------------------------------------------------------------------*/
/* SEND ZMODEM (send a file) */
/* returns TRUE (1) for good xfer, FALSE (0) for bad */
/* sends one file per call; 'fsent' flags start and end of batch */
/*--------------------------------------------------------------------------*/
int Send_Zmodem (char *fname, char *alias, int fsent, int wazoo)
{
register byte *p;
register byte *q;
struct stat f;
int i;
int rc = TRUE;
char j[100];
#ifdef DEBUG
show_debug_name ("send_Zmodem");
#endif
IN_XON_ENABLE ();
z_size = 0;
Infile = NULL;
if (fname && !(fullscreen && un_attended))
set_xy ("");
switch (fsent)
{
case 0:
Z_PutString ((byte *)"rz\r");
Z_PutLongIntoHeader (0L);
Z_SendHexHeader (ZRQINIT, (byte *)Txhdr);
/* Fall through */
case NOTHING_TO_DO:
Rxtimeout = 200;
if (ZS_GetReceiverInfo () == ERROR)
{
XON_DISABLE ();
XON_ENABLE ();
return FALSE;
}
}
Rxtimeout = (int) (614400L / (long) cur_baud.rate_value);
if (Rxtimeout < 100)
Rxtimeout = 100;
if (fname == NULL)
goto Done;
/*--------------------------------------------------------------------*/
/* Prepare the file for transmission. Just ignore file open errors */
/* because there may be other files that can be sent. */
/*--------------------------------------------------------------------*/
Filename = fname;
CLEAR_IOERR ();
if ((Infile = share_fopen (Filename, read_binary, DENY_WRITE)) == NULL)
{
(void) got_error (MSG_TXT(M_OPEN_MSG), Filename);
rc = OK;
goto Done;
}
if (isatty (fileno (Infile)))
{
errno = 1;
(void) got_error (MSG_TXT(M_DEVICE_MSG), Filename);
rc = OK;
goto Done;
}
/*--------------------------------------------------------------------*/
/* Send the file */
/* Display outbound filename, size, and ETA for sysop */
/*--------------------------------------------------------------------*/
(void) stat (Filename, &f);
i = (int) (f.st_size * 10 / cur_baud.rate_value + 53) / 54;
(void) sprintf (j, "Z-Send %s, %ldb, %d min.", Filename, f.st_size, i);
file_length = f.st_size;
if (un_attended && fullscreen)
{
clear_filetransfer ();
sb_move ( file_hWnd, 1, 2);
FlLnModeSet( FILE_LN_2, 1 );
sb_puts( GetDlgItem( file_hWnd, FILE_LN_1 ), j );
elapse_time ();
(void